package action;

 

import com.opensymphony.xwork2.ActionSupport;

import vo.User;

import dao.UserMapper;

import org.apache.struts2.interceptor.ServletRequestAware;

import javax.servlet.http.HttpServletRequest;

 

public class IndexAction extends ActionSupport implements  ServletRequestAware{

private String user;

private String password;

private String id;

HttpServletRequest request = null;

private UserMapper userMapper;

public String index(){

return "success";

}

public String select(){

String result = "fail";

try{

User u=new User();

u.setUsername(user);

request.setAttribute("result", userMapper.selectUser(u));

result = "success";

}catch(Exception e){

result = "fail";

}

return result;

}

 

public String insert(){

String result = "fail";

try{

User u=new User();

u.setUsername(user);

u.setPassword(password);

userMapper.insertUser(u);

result = "success";

}catch(Exception e){

result = "fail";

}

return result;

}

public String update(){

String result = "fail";

try{

User u=new User();

u.setId(Integer.parseInt(id));

u.setUsername(user);

u.setPassword(password);

userMapper.updateUser(u);

result = "success";

}catch(Exception e){

result = "fail";

}

return result;

}

public String delete(){

String result = "fail";

try{

userMapper.deleteUser(Integer.parseInt(id));

result = "success";

}catch(Exception e){

result = "fail";

}

return result;

}

@Override

public void setServletRequest(HttpServletRequest request) {

// TODO Auto-generated method stub

this.request = request;

}

public String getUser() {

return user;

}

 

public void setUser(String user) {

this.user = user;

}

 

public String getPassword() {

return password;

}

 

public void setPassword(String password) {

this.password = password;

}

public String getId() {

return id;

}

 

public void setId(String id) {

this.id = id;

}

 

public UserMapper getUserMapper() {

return userMapper;

}

 

public void setUserMapper(UserMapper userMapper) {

this.userMapper = userMapper;

}

}
